package com.zhongjinkang.rhythm.AppView.Adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.zhongjinkang.rhythm.databinding.AdapterItemBinding
import com.zhongjinkang.rhythm.databinding.AdapterItemLongBinding
import com.zhongjinkang.rhythm.uiBean.PortrayBean

class HomeAdapter(var list: List<PortrayBean>, private val context: Context) :
    RecyclerView.Adapter<HomeAdapter.ViewHolder>() {


    override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList<Any>) {
        super.onBindViewHolder(holder, position, payloads)

    }


//    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
//        if (position % 2 == 1) {
//            ( holder as ViewHolder1).bindData(list[position])
//        } else {
//            ( holder as ViewHolder2).bindData(list[position])
//
//        }
//    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        return if (viewType == 1)
            return ViewHolder(AdapterItemBinding.inflate(LayoutInflater.from(context)))
        else
            return ViewHolder(AdapterItemLongBinding.inflate(LayoutInflater.from(context)))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        if (position % 2 == 1) {
            (holder.binding as AdapterItemBinding).portrayBean = list[position]
        }else{
            (holder.binding as AdapterItemLongBinding).portrayBean = list[position]

        }
    }


    override fun getItemViewType(position: Int): Int {
        return if (position % 2 == 1) {
            1;
        } else {
            0
        }
    }


    inner class ViewHolder(val binding: ViewBinding) :
        RecyclerView.ViewHolder(binding.root) {


    }


}


